using UnityEngine;
using System.Collections;

public class Opening : MonoBehaviour {
	
	
	
	GUIStyle style = new GUIStyle();
	
	
	float textPosY = Screen.height/2 -350;
	float textPosX = Screen.width/2 - 250;
	
	int clock = 0;
	
	string text;
	
	
	// X + Left; Y + Frount;  Z + down;  <-rotation caused
	public GameObject fastPrefab;	
	private GameObject fastControl;
	
	public GameObject typePrefab;	
	private GameObject typeControl;
	
	public GameObject extremePrefab;	
	private GameObject extremeControl;	
	
		
	void Start () {
		fastControl = (GameObject) Instantiate(fastPrefab,new Vector3(0, 0.5f, -16), Quaternion.identity);
		fastControl.transform.Rotate( 90f, 180f, 0f);
		typeControl = (GameObject) Instantiate(typePrefab,new Vector3(0, -1.5f, -16), Quaternion.identity);
		typeControl.transform.Rotate( 90f, 180f, 0f);
		extremeControl = (GameObject) Instantiate(extremePrefab,new Vector3(0, -3.5f, -16), Quaternion.identity);
		extremeControl.transform.Rotate( 90f, 180f, 0f);
		
	}
	
	void Update () {
		clock ++;
		if(clock < 10){
			text = "T";
		}		
		else if (clock >= 10 && clock < 20){
			text = "Th";		
		}
		else if (clock >= 20 && clock < 30){
			text = "Thi";		
		}
		else if (clock >= 30 && clock < 40){
			text = "Thin";		
		}
		else if (clock >= 40 && clock < 50){
			text = "Think";		
		}
		else if (clock >= 50 && clock < 60){
			text = "Think ";		
		}
		else if (clock >= 60 && clock < 70){
			text = "Think y";		
		}
		else if (clock >= 70 && clock < 80){
			text = "Think yo";		
		}
		else if (clock >= 80 && clock < 90){
			text = "Think you";		
		}
		else if (clock >= 90 && clock < 100){
			text = "Think you ";		
		}
		else if (clock >= 100 && clock < 110){
			text = "Think you c";		
		}
		else if (clock >= 110 && clock < 120){
			text = "Think you ca";		
		}
		else if (clock >= 120 && clock < 130){
			text = "Think you can";		
		}
		else if (clock >= 130 && clock < 140){
			text = "Think you can ";		
		}
		else if (clock >= 140 && clock < 150){
			text = "Think you can t";		
		}
		else if (clock >= 150 && clock < 160){
			text = "Think you can typ";		
		}
		else if (clock >= 160 && clock < 170){
			text = "Think you can type";		
		}
		else if (clock >= 170 && clock < 180){
			text = "Think you can type ";		
		}
		else if (clock >= 180 && clock < 190){
			text = "Think you can type f";		
		}
		else if (clock >= 190 && clock < 200){
			text = "Think you can type fa";		
		}
		else if (clock >= 200 && clock < 210){
			text = "Think you can type fas";		
		}
		else if (clock >= 210 && clock < 220){
			text = "Think you can type fast";		
		}
		else if (clock >= 220 && clock < 230){
			text = "Think you can type fast ";		
		}
		else if (clock >= 230 && clock < 240){
			text = "Think you can type fast e";		
		}
		else if (clock >= 240 && clock < 250){
			text = "Think you can type fast en";		
		}
		else if (clock >= 250 && clock < 260){
			text = "Think you can type fast eno";		
		}
		else if (clock >= 260 && clock < 270){
			text = "Think you can type fast enou";		
		}
		else if (clock >= 270 && clock < 280){
			text = "Think you can type fast enoug";		
		}
		else if (clock >= 280 && clock < 290){
			text = "Think you can type fast enough";		
		}
		else if (clock >= 290 && clock < 300){
			text = "Think you can type fast enough?";		
		}
		
		else if (clock >= 360 && clock < 370){
			text = "Think you can type fast enough? \n" +
				   "T";
		}
		else if (clock >= 360 && clock < 380){
			text = "Think you can type fast enough? \n" +
				   "Th";
		}
		else if (clock >= 370 && clock < 390){
			text = "Think you can type fast enough? \n" +
				   "Thi";
		}
		else if (clock >= 380 && clock < 400){
			text = "Think you can type fast enough? \n" +
				   "Thin";
		}
		else if (clock >= 390 && clock < 410){
			text = "Think you can type fast enough? \n" +
				   "Think";
		}
		else if (clock >= 400 && clock < 420){
			text = "Think you can type fast enough? \n" +
				   "Think ";
		}
		else if (clock >= 410 && clock < 430){
			text = "Think you can type fast enough? \n" +
				   "Think a";
		}
		else if (clock >= 420 && clock < 440){
			text = "Think you can type fast enough? \n" +
				   "Think ag";
		}
		else if (clock >= 430 && clock < 450){
			text = "Think you can type fast enough? \n" +
				   "Think ag";
		}
		else if (clock >= 440 && clock < 460){
			text = "Think you can type fast enough? \n" +
				   "Think aga";
		}
		else if (clock >= 450 && clock < 470){
			text = "Think you can type fast enough? \n" +
				   "Think agai";
		}
		else if (clock >= 460 && clock < 480){
			text = "Think you can type fast enough? \n" +
				   "Think again";
		}
		else if (clock >= 470 && clock < 490){
			text = "Think you can type fast enough? \n" +
				   "Think again.";
		}
		
		else if (clock >= 540 && clock < 570){
			fastControl.transform.Translate( 0, -0.5f, 0);
		}
		else if (clock >= 570 && clock < 600){
			if (clock % 2 == 0 ){
				fastControl.transform.Translate( 0.02f, 0, 0);
				fastControl.transform.Rotate( 0, 2, 0);
			}else if (clock % 2 == 1){
				fastControl.transform.Translate( -0.02f, 0, 0);
				fastControl.transform.Rotate( 0, -2, 0);
			}
		}
		else if (clock >= 600 && clock < 630){
			typeControl.transform.Translate( 0, -0.5f, 0);
		}
		else if (clock >= 630 && clock < 660){
			if (clock % 2 == 0 ){
				typeControl.transform.Translate( 0.02f, 0, 0);
				typeControl.transform.Rotate( 0, 2, 0);
			}else if (clock % 2 == 1){
				typeControl.transform.Translate( -0.02f, 0, 0);
				typeControl.transform.Rotate( 0, -2, 0);
			}
		}
		else if (clock >= 660 && clock < 690){
			extremeControl.transform.Translate( 0, -0.5f, 0);
		}
		else if (clock >= 690 && clock < 720){
			if (clock % 2 == 0 ){
				extremeControl.transform.Translate( 0.02f, 0, 0);
				extremeControl.transform.Rotate( 0, 2, 0);
			}else if (clock % 2 == 1){
				extremeControl.transform.Translate( -0.02f, 0, 0);
				extremeControl.transform.Rotate( 0, -2, 0);
			}
		}
		
		else if(clock > 800){
			Application.LoadLevel("Menu");
		}
	}
	
	void OnGUI () {
		style.fontSize = 48;
	   	style.normal.textColor=Color.white;
	   	style.alignment=TextAnchor.MiddleCenter;
		GUI.Label (new Rect (textPosX, textPosY, 500, 300), 
		text			
		,style);
		
	}
}
  